package graphs;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.Collection;
import tester.Example;
import tester.TestMethod;
import tester.Tester;
import tester.cobertura.Instrument;

/**
 * <h1> Title : Link </h1>
 * <p> Description : Represents the path or link between two points and it's weight. </p> 
 * 
 * @author Adam Blackwell & Ryan Cassidy
 * @since February 22nd 2009
 * @version 1.2
 */
@Instrument @Example public class Link {
  private Vertex destinationVertex;
  private int    weight;
  private boolean visited;

  /**
   * @param startVertex
   * @param destinationVertex
   * @param visited
   */
  public Link(int weight, Vertex destinationVertex, boolean visited) {
    this.destinationVertex = destinationVertex;
    this.weight = weight;
    this.visited = visited;
  }
  
  /**
   * @param startVertex
   * @param destinationVertex
   * @param visited
   */
  public Link(Vertex startVertex, Vertex destinationVertex, boolean visited) {
    this.destinationVertex = destinationVertex;
    this.weight = ((int) startVertex.distanceTo(destinationVertex));
    this.visited = visited;
  }

  /**
   * <p> Constructor : </p> 
   * 
   * @param startVertex
   * @param destinationVertex
   */
  public Link(Vertex startVertex, Vertex destinationVertex) {
    this.destinationVertex = destinationVertex;
    this.weight = ((int) startVertex.distanceTo(destinationVertex));
    this.visited = false;
  }
  
  /**
   * <p> Constructor : </p> 
   * 
   * @param weight
   * @param destinationVertex
   */
  public Link(int weight, Vertex destinationVertex) {
    this.destinationVertex = destinationVertex;
    this.weight = weight;
    this.visited = false;
  }
  
  public Link() {
    /* In order to properly have a default destination vertex I would need to parameterize Link. */
    this.weight = -1;
    this.visited = false;
  }

  /**
   * <p> GetWeight: returns the {weight} field's value. </p> 
   * 
   * @return the weight
   */
  public int getWeight() {
    return this.weight;
  }
  
  /**
   * <p> SetWeight : changes the {weight} to the given integer. </p> 
   * 
   * @param weight
   */
  public void setWeight(int weight) {
    this.weight = weight;
  }
  
  
  public boolean isVisited() {
    return visited;
  }

  public void setVisited(boolean visited) {
    this.visited = visited;
  }
  
  /*
   * (non-Javadoc)
   * @see graphs.ILink#getDestinationVertex()
   */
  public Vertex getDestinationVertex() {
    return this.destinationVertex;
  }
  
//  /**
//   * <p> Draw : Draws the link on the given graphics object. </p> 
//   * 
//   * @param g
//   * @param sp
//   */
//  public void draw(Graphics g, Vertex sp) {
//    g.setColor(Color.BLACK);
//    g.drawLine(sp.getLoc().x, sp.getLoc().y, destinationVertex.getLoc().x,
//               destinationVertex.getLoc().y);
//  }
  
  /**
   * <p> CompareTo : Compares two links and their weights. </p> 
   * 
   * @param that
   * @return the difference in weight
   */
  public int compareTo(Link that) {
    // Checks if this weight is less than that.
    return this.weight - ((Link)that).weight;
  }
  
  // =================================================================
  // Tests:
  // =================================================================
  
  @TestMethod public void test1(Tester t) {
    t.checkExpect(true);
  }
  
  @TestMethod public void test2(Tester t) {
    t.checkExpect(true);
  }
  
  @TestMethod public void test3(Tester t) {
    t.checkExpect(true);
  }
  
  @TestMethod public void test4(Tester t) {
    t.checkExpect(true);
  }
  
  @TestMethod public void test5(Tester t) {
    t.checkExpect(true);
  }
}
